//
//  RWOrderRemarksViewController.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/14.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "RWOrderRemarksViewController.h"

@interface RWOrderRemarksViewController ()

@property (nonatomic, strong) UITextView *orderRemarksTV;

@end

@implementation RWOrderRemarksViewController

#pragma mark - View LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initObjects];
    [self loadDatas];
    [self setNavigation];
    [self setOrderRemarksUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Load Datas

- (void)initObjects{

}

- (void)loadDatas{    
    
    [FTYHTTPManager postInfoWithSubUrl:[NSString stringWithFormat:@"/shop/ybkapi.php?act=ybkapi&op=addresslist&member_id=%@", [FTYUser sharedUser].userID] parameters:nil block:^(id result, NSError *error) {
        if (!error) {
            
            DLog(@"====%@", result);
            FTYBaseModel *baseModel = [[FTYBaseModel alloc] init];
            baseModel = [FTYBaseModel mj_objectWithKeyValues:result];
            FTYErrorInfoModel *errorInfo = [FTYErrorInfoModel mj_objectWithKeyValues:baseModel.err];
            
            if (0 == errorInfo.errorcode) {
                
            } else {
                [[FTYToastView alloc] addTitle:errorInfo.errorinfo addView:self.view];
            }
        } else {
            DLog(@"地址获取信息失败：%@", result);
        }
    }];
}

#pragma mark - Config UI

- (void)setNavigation{
    
    self.title = @"订单备注";
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(0, 0, 40.*FTY_WIDTH_BASE, 30.*FTY_HEIGHT_BASE);
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[FTYColor whiteColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = FTY_FONTTSIZE(18);
    [saveBtn addTarget:self action:@selector(saveBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:saveBtn];
    self.navigationItem.rightBarButtonItem = rightBarBtnItem;
}

- (void)setOrderRemarksUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITextView *orderRemarksTV = [[UITextView alloc] init];
    [self.view addSubview:orderRemarksTV];
    orderRemarksTV.text = @"在这可以写下你的备注哦～";
    orderRemarksTV.backgroundColor = [FTYColor getEEEEEEColorWithAlpha:1.];
    [orderRemarksTV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(10.*FTY_HEIGHT_BASE);
        make.right.mas_offset(-10.*FTY_WIDTH_BASE);
        make.height.mas_offset(150.*FTY_HEIGHT_BASE);
    }];
    _orderRemarksTV = orderRemarksTV;
}

#pragma mark - Config UI

#pragma mark - Config Invoke Methods

#pragma mark - Notification Method

#pragma mark - Notification Invoke Methods

#pragma mark - <UITableViewDataSource>

#pragma mark - <UITableViewDelegate>

#pragma mark - Private Invoke Methods

- (void)saveBtnAction:(UIButton *)btn{

    [self sendRemarkData];
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)sendRemarkData
{
    NSString *remark = _orderRemarksTV.text;
    if (_delegate && [_delegate respondsToSelector:@selector(sendRemarkData:)]) {
        [_delegate sendRemarkData:remark];
    }
}

@end
